//
//  ST_PushPeculiaritySelectMediaSupplementView.swift
//  btvideo
//
//  Created by mac on 2020/4/28.
//  Copyright © 2020 JarvanZhang. All rights reserved.
//

import UIKit
import SnapKit
import SwifterSwift




class ST_PushPeculiaritySelectMediaSupplementView: UICollectionReusableView {

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = .white
        
        self.addSubview(peculiarity_image_view)
        peculiarity_image_view.snp.makeConstraints { (make) in
            make.width.height.equalTo(100)
            make.top.equalToSuperview().offset(20)
            make.centerX.equalToSuperview()
        }
        
        self.addSubview(peculiarity_title_label)
        peculiarity_title_label.snp.makeConstraints { (make) in
            make.top.equalTo(peculiarity_image_view.snp.bottom).offset(15)
            make.centerX.equalToSuperview()
        }
        
        self.addSubview(type_label)
        type_label.snp.makeConstraints { (make) in
            make.top.equalTo(peculiarity_title_label.snp.bottom).offset(5)
            make.centerX.equalToSuperview()
            make.height.equalTo(20)
            make.width.equalTo(50)
        }
        
        self.addSubview(love_number_btn)
        love_number_btn.snp.makeConstraints { (make) in
            make.top.equalTo(type_label.snp.bottom).offset(14)
            make.centerX.equalToSuperview()
            make.height.equalTo(30)
            make.width.equalTo(100)
        }
        
        self.addSubview(content_label)
        content_label.snp.makeConstraints { (make) in
            make.top.equalTo(love_number_btn.snp.bottom).offset(15)
            make.centerX.equalToSuperview()
            make.left.equalToSuperview().offset(27)
            make.right.equalToSuperview().offset(-28)
        }
        
        let bottomOffset = -65
        
        self.addSubview(record_image_view)
        record_image_view.snp.makeConstraints { (make) in
            make.top.equalTo(content_label.snp.bottom).offset(51)
            make.left.equalTo(peculiarity_image_view).offset(bottomOffset)
            make.width.height.equalTo(80)
        }
        
        
        self.addSubview(photo_image_view)
        photo_image_view.snp.makeConstraints { (make) in
            make.top.equalTo(record_image_view)
            make.right.equalTo(peculiarity_image_view).offset(bottomOffset * -1)
            make.width.height.equalTo(record_image_view)
        }
        
        self.addSubview(record_label)
        record_label.snp.makeConstraints { (make) in
            make.top.equalTo(record_image_view.snp.bottom).offset(15)
            make.centerX.equalTo(record_image_view)
        }
        
        self.addSubview(photo_label)
        photo_label.snp.makeConstraints { (make) in
            make.top.equalTo(photo_image_view.snp.bottom).offset(15)
            make.centerX.equalTo(photo_image_view)
        }
        
        
        self.addSubview(record_btn)
        record_btn.snp.makeConstraints { (make) in
            make.left.right.top.equalTo(record_image_view)
            make.bottom.equalTo(record_label)
        }
        
        self.addSubview(photo_btn)
        photo_btn.snp.makeConstraints { (make) in
            make.left.right.top.equalTo(photo_image_view)
            make.bottom.equalTo(photo_label)
        }
        
        self.addSubview(bottom_label)
        bottom_label.snp.makeConstraints { (make) in
            make.centerX.equalToSuperview()
            make.bottom.equalToSuperview().offset(-5)
        }
        
        
        
        bind_control_value()
        
    }
    
    
    fileprivate func bind_control_value(){
        
        guard  let currModel = willPushPeculiarity else { return  }
        
                
        peculiarity_image_view.pin_setImage(from: currModel.image.compress_image().url, placeholderImage: ST_SwiftConst.shared.fetch_random_place_holder_image())
        
        peculiarity_title_label.text = currModel.name
        
        type_label.text = currModel.descriptionStr
        type_label.snp.updateConstraints { (make) in
            make.width.equalTo(currModel.descriptionStr.width(withConstrainedHeight: 100, font:  UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)) + 22)
        }
        
        var text = currModel.like_num.st_number_description()+"个女生喜欢"
        if let sex = ST_BTUserInfoManager.shared.current_account_info?.userinfo?.sex , sex == .female{
            text = currModel.like_num.st_number_description()+"个男生喜欢"
        }
        
        love_number_btn.setTitleForAllStates(text)
        
        let loveNumberBtnW = text.width(withConstrainedHeight: 100, font: UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)) + 41 + 14
        
        love_number_btn.snp.updateConstraints { (make) in
            make.width.equalTo(loveNumberBtnW)
        }
        
        
        let attrString = NSMutableAttributedString(string: currModel.intro)
        
        let parag = NSMutableParagraphStyle()
        parag.lineSpacing = 5
        parag.alignment = .center
        let attr: [NSAttributedString.Key : Any] = [.font: UIFont.systemFont(ofSize: 14),.foregroundColor: UIColor(red: 0.2, green: 0.2, blue: 0.2, alpha: 1),NSAttributedString.Key.paragraphStyle:parag]
        
        attrString.addAttributes(attr, range: NSRange(location: 0, length: attrString.length))
        
        
        content_label.attributedText = attrString
        
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
//    MARK: - Properties
    fileprivate lazy var peculiarity_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.cornerRadius = 20
        return control
    }()
    
    
     fileprivate lazy var peculiarity_title_label:UILabel = {
        let control = UILabel.init()
        control.text = ""
        control.textColor = Color.init(hexString: "#333333")
//        control.numberOfLines = 0
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 20, weight: UIFont.Weight.semibold)
        return control
    }()
    
     fileprivate lazy var type_label:UILabel = {
        let control = UILabel.init()
        control.text = " "
        control.textColor = Color.init(hexString: "#61666F")
        control.backgroundColor = Color.init(hexString: "#F2F4F7")
        control.cornerRadius = 10
//        control.numberOfLines = 0
        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.regular)
        return control
    }()
    
    
    
    
    fileprivate lazy var love_number_btn:UIButton = {
        
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.backgroundColor = Color.white
        control.cornerRadius = 15
        control.borderColor = Color.init(hexString: "#ED3E58")
        control.borderWidth = 2
        control.titleEdgeInsets = UIEdgeInsets.init(top: 0, left: 6, bottom: 0, right: 0)
//        control.setTitleForAllStates("来一起拍视频啦")
        control.setTitleColorForAllStates(UIColor.init(hexString: "#ED3E58")!)
        control.setImageForAllStates(ST_ImageUtils.imageName("首页_icon_X个喜欢")!)
        control.titleLabel?.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)
        return control
    }()
    
    
    fileprivate lazy var content_label:UILabel = {
        let control = UILabel.init()
        control.numberOfLines = 0
        control.textAlignment = .center
        return control
    }()
    
    
    
    fileprivate lazy var record_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.image = ST_ImageUtils.imageName("首页_bot_视频")
        return control
    }()
    
    fileprivate lazy var record_label:UILabel = {
        let control = UILabel.init()
        control.text = "视频"
        control.textColor = Color.init(hexString: "#333333")
//        control.numberOfLines = 0
//        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)
        return control
    }()
    
    fileprivate lazy var record_btn:UIButton = {
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.addTarget(self, action: #selector(record_btn_click), for: UIControl.Event.touchUpInside)
        return control
    }()
    
    fileprivate lazy var photo_image_view:UIImageView = {
        let control = UIImageView()
        control.contentMode = UIView.ContentMode.scaleAspectFill
        control.image = ST_ImageUtils.imageName("首页_icon_相册")
        return control
    }()
    
    fileprivate lazy var photo_label:UILabel = {
        let control = UILabel.init()
        control.text = "图片"
        control.textColor = Color.init(hexString: "#333333")
//        control.numberOfLines = 0
//        control.textAlignment = .center
        control.font = UIFont.systemFont(ofSize: 14, weight: UIFont.Weight.medium)
        return control
    }()
    
    fileprivate lazy var photo_btn:UIButton = {
        let control = UIButton.init(type: UIButton.ButtonType.custom)
        control.add_touch_up(insideTarget: self, action: #selector(photo_btn_click))
        return control
    }()
    
    
    lazy var bottom_label:UILabel = {
        let control = UILabel.init()
        control.text = "别人此类特质"
        control.textColor = Color.init(hexString: "#61666F")
        control.font = UIFont.systemFont(ofSize: 17, weight: UIFont.Weight.semibold)
        control.isHidden = true
        return control
    }()
    
    var photo_btn_click_closure:(()->())?
    
    var record_btn_click_closure:(()->())?
    
}


//MARK: - Event
extension ST_PushPeculiaritySelectMediaSupplementView{
    
    @objc func photo_btn_click(){
        
        photo_btn_click_closure?()
        
    }
    
    
    @objc func record_btn_click(){
        
        record_btn_click_closure?()
        
    }
}
